package thread;

public class Thread_interrupt2 {

    private static volatile boolean flag = false;

    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while (!flag) {
                System.out.println("打游戏...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        thread.start();
        try {
            Thread.sleep(2*1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("要吃饭了，别打游戏了!");
        flag = true;
    }
}
